package com.lzx.adx.report.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.lzs.adx.commmon.cache.LocalCache;
import com.lzs.adx.commmon.service.impl.CrudServiceImpl;
import com.lzx.adx.report.cache.AccountLocalCache;
import com.lzx.adx.report.dao.AccountDao;
import com.lzx.adx.report.dto.AccountDTO;
import com.lzx.adx.report.entity.AccountEntity;
import com.lzx.adx.report.service.AccountService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class AccountServiceImpl extends CrudServiceImpl<AccountDao, AccountEntity, AccountDTO> implements AccountService {

    @Override
    public QueryWrapper<AccountEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<AccountEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public void sysnCacheToDb() {
        List<AccountDTO> list = this.list(new HashMap<>());
        for(AccountDTO accountDTO:list){
            AccountLocalCache.getInstance().put(String.valueOf(accountDTO.getId()),accountDTO);
        }

    }
}